package saii.business;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import org.apache.log4j.Logger;
import org.apache.log4j.BasicConfigurator;

import saii.business.bbdd.BBDDEIntermedio;
import saii.business.modelo.Alumno;

public class PruebasMediador {

	public static void main(String[] args) throws SQLException {

		
		// Variables para el log
		Logger log = Logger.getLogger("PruebasMediador.java");

		// Configuro el log
		BasicConfigurator.configure();

		BBDDEIntermedio wp = new BBDDEIntermedio();
		
		Mediador med = new Mediador();
		
//		Alumno a1,a2;
		
//		a1 = new Alumno("1234","mozo", "mozo1", "mozo2", "17/8/1990","983356765", "a@a.com", "aaaa");
//		a2 = new Alumno("1234","moza", "mozo3", "mozo4", "17/8/1990","983356765", "a@a.com", "ND");
//		
//		try {
//			Alumno af = (Alumno) med.uneGenerico(a1, a2);
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
		
		String query = "SELECT * FROM eIntermedio.ALUMNOS";
		
		ArrayList<String> lisTablas = med.parseSQL(query);
		
		
		
		med.selectorDatos(lisTablas);
		
	
		
		ArrayList<Alumno> al = med.listAlumnos;

		
		for (int i=0;i<al.size();i++){
			log.trace(al.get(i).toString());
		}
		
		// For para llenar la lista de inserts
		
		ArrayList<String> listaInsert = new ArrayList<String>();
		
		for (int i=0;i<al.size();i++){
			listaInsert.add(al.get(i).getRowInsert());
		}
		
		wp.inserta("ALUMNOS", listaInsert);
		
		ResultSet rs = wp.ejecutaQuery(query);
		
		log.trace("Valores de la BBDD");
		while(rs.next()){
			
			log.trace(rs.getString("dni")+"\t"+rs.getString("nombre")+"\t"+rs.getString("apellidos1")+"\t"+rs.getString("apellidos2")+"\t"+rs.getString("fnac")+"\t"+rs.getString("numTelefono")+"\t"+rs.getString("email")+"\t"+rs.getString("direccion"));
			
		}

		
		
	}
}
